{% include 'header.html' %}
<p>&nbsp;</p>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.60.0/codemirror.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.60.0/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"></script>
<form class="layui-form" id="userform" action="/projects/project/deploy_exec" method="POST">
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">id</label>
        <div class="layui-input-block">
            <input type="text" name="id" value="{{ obj['id'] }}" disabled="true" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">项目名</label>
        <div class="layui-input-block">
            <input type="text" name="project_name" value="{{ obj['project_name'] }}" required  disabled="true" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">版本号</label>
        <div class="layui-input-block">
            <input type="text" name="version_no" value="" required  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择git仓库</label>
        <div class="layui-input-block">
        <select name="git_data" lay-verify="required">
            {% for git in gitData %}
            <option value="{{ git['id'] }}|https://{{ git['username'] }}:{{ git['password'] }}@{{ git['uri'] }}">{{ git['repos_name'] }}({{ git['uri'] }})</option>
            {% endfor %}
        </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择安装主机</label>
        <div class="layui-input-block">
        <select name="host_data" lay-verify="required">
            {% for host in hostData %}
            <option value="{{ host['id'] }}|{{ host['ip'] }}">{{ host['server_name'] }}({{ host['ip'] }})</option>
            {% endfor %}
        </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
layui.use('form', function(){
  var form = layui.form;

  // 监听提交事件
  form.on('submit(formDemo)', function(data){
    // 阻止表单默认提交行为
    // data.preventDefault(); // 如果使用这行代码也可以阻止默认提交
    var field = data.field; // 获取表单所有字段，包含提交按钮的name值

    var loading = layer.load(2, {time: 300*1000});

    // 使用Ajax进行异步提交
    layui.jquery.ajax({
      url: '/projects/project/deploy_exec', // 服务器接口
      type: 'post',
      contentType: 'application/json',
      data: JSON.stringify(data.field), // 将表单数据转为JSON字符串
      success: function(res){
        layer.close(loading);
        window.location.href='/projects/task/list'
      }
    });

    // 返回false阻止表单默认提交
    return false;
  });
});
</script>
{% include 'footer.html' %}